#include "read.h"
#include "package.h"
#include "print.h"
#include "mm.h"
#include "info.h"
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "error.h"
#include "eval.h"

int main(int argc, char *argv[])
{
  int i;
  int isOpen=0;
  initLexical(NULL);
  if(argc>1)
    {
      for(i=1; i<argc;i++)
	{
	  if(!strcmp(argv[i],"--use") ||
	     !strcmp(argv[i],"-u"))
	    {
	      /*EngineWorking();*/
	      MMInit();
	      import_file(argv[i+1],0);
	      switchStdin();
	      isOpen = 1;
	      i++;
	    }else{
	    printf("%s %s\n",APP_PRJ_NAME,APP_VERSION);
	    printf("wrong switch\n");
	    printf("help;\n\t[-u|--use] ; open a file with the main function\n");
	    exit(-1);
	  }
	}
    }
  if(0)/*isOpen) */
    {
      /*eval(Cons(MMWord("main"),MMNil())); */
      exit(-1);
      MMDelete();
      deleteLexical();
    }
  
  /* interactive mode */
  printf("%s %s\n",APP_PRJ_NAME,APP_VERSION);

  /*EngineWorking();*/
  MMInit();
  if (! ERRORInit() )
    {
      STACKInit();
    }else{
    STACKRestart();
    /* TODO: ATENTION COMRADE: THIS MAY FUCKUP with multiple files */
    restartLexical();
  }
  while(1)
    {
      STACKPush(MYread());
      eval(StackPOP());
      print(STACKPop());
      restartLexical();
    }
  return 0;
  MMDelete();
  deleteLexical();
}
